<!DOCTYPE html public '-//W3C//DTD HTML 4.01//EN'
  'http://www.w3.org/TR/html4/strict.dtd'>
<html lang="en">
 <head>
  <title>Selecting a media type on bandwidth-constrained handheld devices</title>
  <link rel="author" title="Ian Hickson" href="mailto:ian@hixie.ch"/>
  <link rel="alternate" href="http://www.hixie.ch/tests/adhoc/css/media/handheld/specification.html"/>
  <link rel="help" href="http://www.w3.org/TR/CSS2/media.html#media-sheets" />
  <link rel="stylesheet" type="text/css" href="http://www.hixie.ch/resources/style/specification.en">
 </head>
 <body draft="spec">

<div class="head">
<p><a rel="home" href="http://www.opera.com/" class="logo"><img alt="Opera Software" src="http://www.opera.com/graphics/logos/opera.png"></a></p>

<h1>Selecting a media type on bandwidth-constrained handheld devices</h1>

<h2 class="no-num no-toc">Opera Working Draft, July 17th 2003</h2>
<dl>
<!--
  <dt>This version:</dt>
    <dd><a
      href="./">./</a></dd>
  <dt>Latest version:</dt>
    <dd><a
      href="./">./</a></dd>
  <dt>Previous version:</dt>
    <dd><a
      href="./">./</a></dd>
-->
  <dt>Editor:</dt>
    <dd>Ian Hickson, Opera Software, ian@hixie.ch</dd>
 </dl>
 <p class="copyright">&copy; Copyright 2003 Opera Software.</p>
</div>

<hr>

<h2 class="no-num no-toc" id="abstract">Abstract</h2>

<p>Users of handheld devices expect the Web to the same on their devices as it is on desktops.</p>
<p>Authors of Web sites expect specific control over the rendering of pages on handhelds.</p>
<p>Most Web sites are not designed for handheld devices, so a user stylesheet mode must be provided.</p>
<p>This document describes the technique used to select which mode a bandwidth-constrained handheld device should use.</p>

  <h2><a name="TOC">Table of Contents</a></h2>
  <ul>
   <li><a href="#TOC1">1. Introduction</a></li>
   <li><a href="#TOC2">2. Mode Selection</a>
    <ul>
     <li><a href="#TOC21">2.1. Handheld Stylesheets</a>
     <li><a href="#TOC21">2.2. Mobile DTDs</a>
    </ul>
   </li>
   <li><a href="#TOC3">3. Mode Handling</a></li>
   <li><a href="#TOC4">4. Compliance</a></li>
  </ul>

  <hr>

<h2 id="TOC1">1. Introduction</h2>

<p>This specification describes three modes of operation.</p>

<dl>
 <dt>handheld mode</dt>
 <dd>The preferred mode for handheld devices, this is the spec-compliant handling of CSS stylesheets applied to the document in the context of the <code>handheld</code> media type.</dd>
 <dt>screen mode</dt>
 <dd>In the absence of <code>handheld</code> stylesheets, users should be given the opportunity to switch to this mode, in which the document's CSS stylesheets are applied to the document in the context of the <code>screen</code> media type.</dd>
 <dt>SSR mode</dt>
 <dd>Technically the mode (for which the CSS specifications require support) in which author stylesheets are disabled and the UA uses a custom stylesheet to render the content. This mode is used in preference to the screen mode when the page is not using a mobile DTD and there are no handheld stylesheets available, and is also available from handheld mode in case the handheld stylesheet is unreadable (an unfortunately common occurrence).</dd>
</dl>

<h2 id="TOC2">2. Mode Selection</h2>

<p>There are two features of documents that should be used to decide which mode to use.</p>

<h3 id="TOC21">2.1. Handheld Stylesheets</h3>

<p>When loading a page, the UA must see if any of the embedded inline stylesheets, as well as any links to external stylesheets, mention the <code>handheld</code> media type. This is done without fetching any additional resources. Specifically, this means that during the page load the UA must look for:</p>
<ol>
<li>A value of <code>handheld</code> in the comma separated media pseudo-attribute of <code>&lt;?xml-stylesheet?&gt;</code> PIs.</li>
<li>A value of <code>handheld</code> in the comma separated media attribute of <code>&lt;link&gt;</code> elements that have a value of <code>stylesheet</code> in their space-separated rel attribute.</li>
<li>A value of <code>handheld</code> in the comma separated media attribute of <code>&lt;style&gt;</code> elements.</li>
<li>An <code>@import</code> or </code>@media</code> rule that mentions the <code>handheld</code> media type in a <code>&lt;style type="text/css"&gt;</code> element with a media of <code>all</code> (the default).</li>
<li>If we support HTTP links, then <code>media="handheld"</code> in an HTTP Link header with <code>stylesheet</code> in its space-separated <code>rel</code> attribute.</li>
</ol>

<p>Specifically, in the first three cases, UAs should not take into account the type attributes, UAs should not take into account if the stylesheets are alternates or persistent, and UAs should not download the files to check they mention <code>handheld</code>.</p>

<p>Note that links to stylesheets that use the <code>data:</code> URI scheme must be considered <em>external</em> stylesheets and are not parsed during this exploratory stage. Similarly, even if the external stylesheets are available in the cache, they must be ignored during this stage. In particular, if a document has a single external stylesheet with <code>media="all"</code> containing an <code>@media "handheld" {}</code> block, thus triggering SSR mode (no <code>handheld</code> in the main document), then, if the user switches to <code>screen</code> mode, then goes to another document, then returns to the first document, the UA should not switch into handheld mode, even though it technically knows that there is <code>handheld</code> style on the page (since the stylesheet will be in the cache).</p>

<h3 id="TOC21">2.2. Mobile DTDs</h3>

<p>In addition to checking the given media types to decide whether the page should be in handheld mode, the UA should also check for certain DTDs to decide whether to avoid going into SSR mode, regardless of the handheld mode setting. The following languages should trigger normal, non-SSR mode:</p>

<dl>
 <dt>Compact HTML</dt>
 <dd>Anything with a DOCTYPE exactly matching <code>&lt;!DOCTYPE HTML
 PUBLIC "-//W3C//DTD Compact HTML 1.0 Draft//EN"&gt;</code>.</dd>
 <dt>XHTML Mobile Profile</dt>
 <dd>Anything with a MIME type of
 <code>application/vnd.wap.xhtml+xml</code> (ignoring any MIME type
 attributes such as 'charset'); anything with a MIME type of
 </code>application/xhtml+xml</code> if it has the attribute
 <code>profile</code> with the exact value
 <code>"http://www.wapforum.org/xhtml"</code> (as in
 <code>application/xhtml+xml;profile="http://www.wapforum.org/xhtml"</code>,
 but other attributes, such as 'charset', shouldn't affect whether it
 matches or not &mdash; note that MIME types and MIME parameters are
 case insensitive, but MIME parameter values are not); or, for content
 sent as <code>text/html</code>, anything with a DOCTYPE exactly
 matching either <code>&lt;!DOCTYPE html PUBLIC "-//WAPFORUM//DTD
 XHTML Mobile 1.0//EN"
 "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"&gt;</code> or
 <code>&lt;!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile
 1.1//EN" "http://www.wapforum.org/DTD/xhtml-mobile11.dtd"&gt;</code>.</dd>
 <dt>WML</dt>
 <dd>Anything with a DOCTYPE exactly matching either
 <code>&lt;!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"
 "http://www.wapforum.org/DTD/wml13.dtd"&gt;</code> or
 <code>&lt;!DOCTYPE html PUBLIC "-//WAPFORUM//DTD WML 2.0//EN"
 "http://www.wapforum.org/DTD/wml20.dtd"&gt;</code>. MIME types are
 not used to detect WML because all WML documents must start with one
 of those DOCTYPEs and thus the MIME type check would be
 redundant.</dd>
</dl>

<p>Comparing DOCTYPEs should be done by parsing the DOCTYPE string as
follows. First, the string <code>&lt;!DOCTYPE</code> should be
matched, case insensitively. Then, one or more whitespace characters
should be skipped, and the string <code>html</code> should be matched
case insensitively for CHTML, and case sensitively for WML and XHTML.
Then, one or more whitespace characters should be skipped, and the
string <code>PUBLIC</code> should be matched case insensitively. Then
again, one or more whitespace characters should be skipped, and the
FPI, delimited by matching quotes (either <code>"</code> or
<code>'</code>) should be matched exactly (case sensitively). Then,
for WML and XHTML, but not for CHTML, whitespace characters should be
skipped, and then another string, delimited by matching quotes again,
should be skipped. Finally, for all DOCTYPEs, a character ">" should
be matched.</p>

<p>If any of the above fails to match, then the DOCTYPE is not
considered to be an exact match.</p>

<h2 id="TOC3">3. Mode Handling</h2>

<p>After having checked all these possibilities:</p>

<ol>
 <li>If the UA has found no trace of any <code>handheld</code> styles and no mobile DTDs, then it should switch to SSR mode, and give the user the option to use <code>screen</code> as the media type.</li>
 <li>If the UA found some <code>handheld</code> style using the steps above, then it should use the <code>handheld</code> media type, and give the user the option to switch to SSR mode.</li>
 <li>If the UA found no <code>handheld</code> style but did find a mobile DTD, then it should use the <code>screen</code> media type, and give the user the option to switch to SSR mode.</li>
</ol>

<p>When the device is not in SSR mode all stylesheets that apply to the chosen media type, including any that are linked using the <code>all</code> media and those that are mentioned in the document before the mention of <code>handheld</code>, must be applied. For example, if an <code>all</code> stylesheet is linked before a <code>screen, handheld</code> stylesheet, then the <code>all</code> stylesheet should still be used while in <code>handheld</code> mode).</p>

<h2 id="TOC4">4. Compliance</h2>

<p>In terms of the CSS specification, this model is compliant, with the liberal interpretation being that the device's media type is selected after loading the stylesheet instead of being constant.</p>

</body>
</html>

<!--  LocalWords:  PIs rel HTTP UAs
 -->
